# 设置密码
# 2025/5/7
def check_strength(password: str):
    special_char_asc = {126, 33, 64, 35, 36, 37, 94, 38, 42, 40, 41, 95}

    spec_asc = 0  # 特殊字符的数量
    spec_ctg = set()  # 特殊字符的种类
    capital = 0  # 大写字符的数量
    lower = 0  # 小写字符的数量
    num_cnt = 0  # 数字的数量
    l = len(password)  # 密码长度
    for c in password:
        asc = ord(c)
        if asc in special_char_asc:
            spec_asc += 1
            spec_ctg.add(asc)
        elif ord("A") <= asc < ord("A") + 26:
            capital += 1
        elif ord("a") <= asc < ord("a") + 26:
            lower += 1
        elif ord("0") <= asc < ord("0") + 10:
            num_cnt += 1
        else:  # 如果不是以上任意一种就是非法字符, 直接返回不合法密码
            return 0

    cnt = 0  # 统计出现的种类的数量
    for i in [spec_asc, capital, lower, num_cnt]:
        if i > 0:
            cnt += 1

    if l >= 12 and (cnt == 4 or (cnt >= 3 and len(spec_ctg) >= 3)):
        return 3
    if l >= 8 and cnt >= 2:
        return 2
    if l >= 6:
        return 1

    return 0


if __name__ == '__main__':
    t = int(input())
    inps = []
    for _ in range(t):
        inps.append(input())
    for inp in inps:
        print(check_strength(inp))
